﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Model;

namespace DLL
{
    public class StudentBindTypeEntityDal
    {
       readonly private DAL.SQLHelper sqlhelper = null;

        public StudentBindTypeEntityDal()
        {
            sqlhelper =new DAL.SQLHelper(); 
        }
        #region"根据学号判断学生是否登录过-韩梦甜-2015-12-14"
        /// <summary>
        /// 根据学号判断学生是否登录过-韩梦甜-2015-12-14
        /// </summary>
        /// <param name="studentinfo"></param>
        /// <returns></returns>
        public DataTable SelectStudentByIsUse(StudentBindPaperTypeEntity studentinfo)
        {
            string sql = "select IsUse from StudentBindPaperTypeEntity where studentID=@studentID";
            SqlParameter[] paras = new SqlParameter[]{
                new  SqlParameter("@studentID",studentinfo.StudentID)
                    
            };
            DataTable dt = sqlhelper.ExecuteQuery(sql, paras, CommandType.Text);
            return dt;
        }
        #endregion

        #region"更改用户是否登录过标志-韩梦甜-2015-12-14"
        /// <summary>
        /// 更改用户是否登录过标志-韩梦甜-2015-12-14
        /// </summary>
        /// <param name="studentinfo"></param>
        /// <returns></returns>
        public int UpdateStudentByIsUse(StudentBindPaperTypeEntity studentinfo)
        {
            //StudentBindType 的IsUse属性，0未在线,1在线,2上传失败
            string sql = "Update StudentBindPaperTypeEntity Set IsUse=@IsUse where StudentID=@studentID and TimeTamp=@timetamp";
            SqlParameter[] paras = new SqlParameter[]{
                new  SqlParameter("@studentID",studentinfo.StudentID),
                  new  SqlParameter("@IsUse",studentinfo.IsUse),
                  new SqlParameter ("@timetamp",studentinfo.TimeTamp )
            };
            int  flag = sqlhelper.ExecuteNonQuery(sql, paras, CommandType.Text);
            return flag ;
        }
        #endregion

        #region 根据学号和是否使用查询时间  2015年12月18日21:08:22 李少然
        /// <summary>
        /// 根据学号和是否使用查询时间
        /// </summary>
        /// <param name="studentinfo"></param>
        /// <returns></returns>
        public DataTable SelectStudentByIsUseStudentID(StudentBindPaperTypeEntity studentinfo)
        {
            string sql = "select TimeTamp from StudentBindPaperTypeEntity where studentID=@studentID and IsUse=@isuse";
            SqlParameter[] paras = new SqlParameter[]{
                new  SqlParameter("@studentID",studentinfo.StudentID),
                new SqlParameter ("@isuse",studentinfo.IsUse  )
                    
            };
            DataTable dt = sqlhelper.ExecuteQuery(sql, paras, CommandType.Text);
            return dt;
        }
        #endregion

        #region"根据学号判断学生是否登录过-苑仁杰-2018-12-22"
        /// <summary>
        /// 根据学号判断学生是否登录过-苑仁杰-2015-12-14
        /// </summary>
        /// <param name="studentinfo"></param>
        /// <returns></returns>
        public DataTable SelectStudentByStudentIDTime(StudentBindPaperTypeEntity studentinfo)
        {
            string sql = "select IsUse from StudentBindPaperTypeEntity where studentID=@studentID order by TimeTamp desc";
            SqlParameter[] paras = new SqlParameter[]{
                new  SqlParameter("@studentID",studentinfo.StudentID),
                new  SqlParameter("@TimeTamp",studentinfo.TimeTamp)

            };
            DataTable dt = sqlhelper.ExecuteQuery(sql, paras, CommandType.Text);
            return dt;
        }
        #endregion
    }
}
